﻿describe("Strategies/PointingInside", function () {

    var pointingInside;

    beforeEach(function () {
        pointingInside = new Strategies.PointingInside();
    });

    describe("should find by:", function () {

        it("row", function () {
            var grid = "--9--8--6-6--3--9-7--6--4--4--7--5---7--5--24--5--4--8--63-1--2-3--2--6-8--9--3--";
            var gridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = pointingInside.perform(gridModel);

            //expect
            expect(performResult).toBeTruthy();
            expect(performResult.candidate).toEqual(6);
            var expectedContainingCells = [gridModel.cells[3][4], gridModel.cells[3][5]];
            expect(performResult.containingCells).toEqual(jasmine.arrayContaining(expectedContainingCells));
            var expectedTargetCells = [gridModel.cells[4][5], gridModel.cells[5][4]];
            expect(performResult.targetCells).toEqual(jasmine.arrayContaining(expectedTargetCells));
            expect(performResult.lineCells).toEqual(jasmine.arrayContaining(gridModel.cells[3]));

            var expectedGridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(expectedGridModel);
            expectedGridModel.cells[4][5].candidates.remove(6);
            expectedGridModel.cells[5][4].candidates.remove(6);
            expect(gridModel).toEqual(expectedGridModel);
        });

        it("column", function () {
            var grid = "--5-1-46-3--49-5--64------7-------2-17--5--34-9-------2-4----7--56-32-48-1--4-2--";
            var gridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = pointingInside.perform(gridModel);

            //expect
            expect(performResult.candidate).toEqual(2);
            var expectedContainingCells = [gridModel.cells[0][1], gridModel.cells[1][1]];
            expect(performResult.containingCells).toEqual(jasmine.arrayContaining(expectedContainingCells));
            var expectedTargetCells = [gridModel.cells[1][2], gridModel.cells[2][2]];
            expect(performResult.targetCells).toEqual(jasmine.arrayContaining(expectedTargetCells));
            expect(performResult.lineCells).toEqual(jasmine.arrayContaining(gridModel.cellsByColumn[1]));

            var expectedGridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(expectedGridModel);
            expectedGridModel.cells[1][2].candidates.remove(2);
            expectedGridModel.cells[2][2].candidates.remove(2);

            expect(gridModel).toEqual(expectedGridModel);
        });


    });
});

